import D2Ext

from .CWidget import CWidget
from .Constants import *


class CLabel(CWidget):

    def __init__(self, text="", parent=None):
        super(CLabel, self).__init__(parent)
        self.text = text
        self.font = 1
        self.color = D2Color.WHITE

    def set_text(self, text):
        self.text = text

    def text(self):
        return self.text

    def set_font(self, font):
        self.font = font

    def font(self):
        return self.font

    def text_width(self):
        return D2Ext.View_GetPixelLen(self.text)

    def draw(self):
        D2Ext.View_SetFontSize(self.font)
        D2Ext.View_PrintString(self.text, self.dx, self.dy, self.color, self.opacity)

